<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.sql.Connection"
    import="java.sql.DriverManager"
    import="java.sql.Statement" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>add_do</title>
</head> 
<body>  
	<%  
		request.setCharacterEncoding("utf-8");
		String book_index = request.getParameter("book_index");
		String title = request.getParameter("title");
		String author = request.getParameter("author");
		String publisher = request.getParameter("publisher");
		String publish_time = request.getParameter("publish_time");
		// int category = Integer.parseInt(request.getParameter("category"));
		String category = request.getParameter("category");
		// float price = Float.parseFloat(request.getParameter("price"));
		String price = request.getParameter("price");
		
		// out.println(book_index);
		// out.println("<br/>");
		// out.println(title);
		// out.println("<br/>");
		// out.println(author);
		// out.println("<br/>");
		// out.println(publisher);
		// out.println("<br/>");
		// out.println(publish_time);
		// out.println("<br/>");
		// out.println(category);
		// out.println("<br/>");
		// out.println(price);
		// out.println("<br/>");
		
		Class.forName("com.mysql.jdbc.Driver");
		
		String url = "jdbc:mysql://localhost:3306/test";
		String db_username = "root";
		String db_password = "";
		Connection conn = DriverManager.getConnection(url, db_username, db_password);
		
		Statement stmt = conn.createStatement();
		String sql = "insert into book (book_index, title, author, publisher, publish_time, category, price) values ";
		sql += "('"+ book_index +"', '"+ title +"', '"+ author +"', '"+ publisher +"', DATE('"+ publish_time +"'), "+ category +", "+ price +")";
		// out.println(sql);
		// out.println("<br/>");
		
		int row = stmt.executeUpdate(sql);
		
		stmt.close();
		conn.close();
		
		response.sendRedirect("BookSystem.jsp");
		
		// Boolean message = (row > 0);
		// request.setAttribute("message", message.toString());
		// request.getRequestDispatcher("BookSystem.jsp").forward(request, response);
	%>  
</body>
</html>